import axios, { AxiosRequestConfig } from 'axios';

function useAxios(config: AxiosRequestConfig) {
  const instance = axios.create(Object.assign({}, config))

  instance.interceptors.request.use(config => {
    return config;
  }, error => {
    return Promise.reject(error);
  })

  instance.interceptors.response.use(response => {
    if (response.status === 200) {
      return response.data;
    }
    return Promise.reject(response);
  }, error => {
    return Promise.reject(error);
  })

  return instance
}

const apiClient = useAxios({
  baseURL: '<%= options.ApiBase %>'
});

export {
  apiClient,
}